home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / appl / napsaterm / tel_main.c < prev    next >
C/C++ Source or Header  |  1994-05-14  |  2KB  |  98 lines

  1. /*
  2.  * $Id: tel_main.c,v 3.1 1994/05/14 14:17:07 ppessi Exp $
  3.  *
  4.  * Author: Tomi Ollila <too@cs.hut.fi>
  5.  *
  6.  * Copyright © 1993, 1994   AmiTCP/IP Group, <amitcp-group@hut.fi>
  7.  *                Helsinki University of Technology, Finland.
  8.  *                All rights reserved.
  9.  *
  10.  * Created: Thu Apr  7 13:29:41 1994 too
  11.  * Last modified: Fri May 13 02:42:42 1994 ppessi
  12.  *
  13.  * HISTORY
  14.  * $Log: tel_main.c,v $
  15.  * Revision 3.1  1994/05/14  14:17:07  ppessi
  16.  * initial revision
  17.  *
  18.  * Revision 3.1  1994/04/17  11:31:54  too
  19.  * initial revision
  20.  *
  21.  */
  22.  
  23. #include "telnet.h"
  24. #include <arpa/telnet.h>
  25. #include "tel_opt.h"
  26. #include "tel_subneg.h"
  27. #include "tel_iacout.h"
  28.  
  29. long telnetdo(u_char *netbuf, long len)
  30. {
  31.   static u_char prevc;
  32.   static u_char state = 0;
  33.  
  34.   long netlen, i;
  35.  
  36. #define touser(c) do { netbuf[netlen++] = c; } while (0)
  37.  
  38.   for (i = 0; i < len; i++) {
  39.     u_char c = netbuf[i];
  40.     
  41.     switch (state) {
  42.     case 0:
  43.       if (c == IAC) {
  44.     netlen = i;
  45.     state = 2;
  46.       }
  47.       break;
  48.     case 1:
  49.       if (c == IAC)
  50.     state = 2;
  51.       else
  52.     touser(c);
  53.       break;
  54.     case 2:
  55.       if (c == IAC) {
  56.     touser(IAC);
  57.     state = 1;
  58.       }
  59.       else {
  60.     switch (c) {
  61.     case SB:
  62.       state = 4;
  63.       break;
  64.     case DO:
  65.     case DONT:
  66.     case WILL:
  67.     case WONT:
  68.       prevc = c;
  69.       state = 3;
  70.       break;
  71.     default:
  72.       state = 0;    /* DATA MARK must be added later */
  73.     }
  74.       }
  75.       break;
  76.     case 3: /* WILL, WONT, DO, DONT */
  77.       telopt(prevc, c);
  78.       state = 1;
  79.       break;
  80.     case 4: /* Subnegotiation */
  81.       if (subneg(c) == TRUE)
  82.     state = 1;
  83.       break;
  84.     }
  85.   }
  86.   iacflush();
  87.   
  88.   if (state != 0) {
  89.     if (state == 1)
  90.       state = 0;
  91.  
  92.     return netlen;
  93.   }
  94.  
  95.   return len;
  96. }
  97.  
  98.